#include <iostream>
#include <vector>
#include <stack>
/*
typedef struct SkiplistNode{
    SkiplistNode* right;
    SkiplistNode* next;
    int key;
    int size;
    SkiplistNode(int k,int s,SkiplistNode* r=nullptr,SkiplistNode* n=nullptr)
    : key(k),size(s),right(r),next(n){}
    ~SkiplistNode(){ right = next = nullptr;}
}SKLNode;

class Skiplist {
public:
    Skiplist() : head(nullptr) {

    }

    ~Skiplist()
    {
        if(head)
        {
            SKLNode* cur = head;
            while(cur)
            {
                SKLNode* nxt = cur->next;
                while(cur)
                {
                    SKLNode* rgh = cur->right;
                    delete(cur);
                    cur = rgh;
                }
                cur = nxt;
            }
        }
    }
    
    bool search(int target) {
        if(!head) return false;
        SKLNode* cur = head;
        while(cur)
        {
            while(cur->right && cur->right->key < target)
            {
                cur = cur->right;
            }
            if(cur->right && cur->right->key == target)
            {
                return true;
            }
            cur = cur->next;
        }
        return false;
    }
    
    void add(int num) {
        //search key , ++ size
        {
            bool bSearch = false;
            SKLNode* cur = head;
            while(cur)
            {
                while(cur->right && cur->right->key < num)
                {
                    cur = cur->right;
                }
                if(cur->right && cur->right->key == num)
                {
                    ++cur->right->size;
                    bSearch = true;
                }
                cur = cur->next;
            }   
            if(bSearch) return ;
        }
        SKLNode* cur = head;
        stack<SKLNode*> stk;
        while(cur)
        {
            while(cur->right && cur->right->key < num)
            {
                cur = cur->right;
            }
            stk.push(cur);
            cur = cur->next;
        }
        // 
        bool bInsert = true;
        SKLNode* nxt = nullptr;
        while(bInsert && !stk.empty())
        {
            SKLNode* back = stk.top();
            stk.pop();
            
            SKLNode* node = new SKLNode(num,1,back->right,nxt);
            back->right = node;
            bInsert = rand()%2 == 0;
            nxt = node;
        }
        if(bInsert)
        {
            //new level
            SKLNode* node = new SKLNode(num,1,nullptr,nxt);
            SKLNode* dummy = new SKLNode(-1,0,node,head);
            head = dummy;
        }
    }
    
    bool erase(int num) {
        //search key , -- size
        bool bSearch = false;
        SKLNode* cur = head;
        while(cur)
        {
            while(cur->right && cur->right->key < num)
            {
                cur = cur->right;
            }
            if(cur->right && cur->right->key == num)
            {
                SKLNode* tmp = cur->right->right;
                --cur->right->size;
                if(cur->right->size == 0)
                {
                    delete(cur->right);
                    cur->right = tmp;
                }
                bSearch = true;
            }
            cur = cur->next;
        }   
        return bSearch;
    }
private:
    SKLNode* head;
};
*/
struct sdshdr {
    
    // buf 中已占用空间的长度
    int len;

    // buf 中剩余可用空间的长度
    int free;

    // 数据空间
    char buf[];
};

int main()
{
    sdshdr s;
    std::cout << &s.len << " " << &s.free << std::endl;
    std::cout << s.buf << std::endl;
    std::cout << sizeof(sdshdr) << std::endl;
    return 0;
}
